package com.erdos.hyt.mall.controller;/**
 * @auth Liurong
 * @date 2017/4/1.
 */

import com.erdos.hyt.base.exception.BaseBizException;
import com.erdos.hyt.base.exception.ExceptionCode;
import com.erdos.hyt.base.model.HytResponse;
import com.erdos.hyt.base.model.ResponseResultHandler;
import com.erdos.hyt.mall.model.MallConsigneeAddress;
import com.erdos.hyt.mall.model.MallGoods;
import com.erdos.hyt.mall.model.MallOrderDetail;
import com.erdos.hyt.mall.service.MallConsigneeAddressService;
import com.erdos.hyt.mall.service.MallGoodsService;
import com.erdos.hyt.mall.service.MallOrderDetailService;
import com.erdos.hyt.users.model.BaseUser;
import com.erdos.hyt.users.service.AppUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
 * 商城商品ctr
 *
 * @author liurong
 * @create 2017/4/1
 **/
@Api(value = "mall API")
@RestController
@RequestMapping(value = "/mall")
public class MallGoodsController {

    public static Logger logger = LoggerFactory.getLogger(MallGoodsController.class);
    @Autowired
    private MallGoodsService mallGoodsService;

    @Autowired
    private MallOrderDetailService mallOrderDetailService;

    @Autowired
    private MallConsigneeAddressService mallConsigneeAddressService;

    @Autowired
    private AppUserService appUserService;


    /*@ApiOperation(value = "商城商品添加",notes="商城商品添加",httpMethod ="GET")
    @RequestMapping(value = "/addMallGoods",method = {RequestMethod.GET},produces ="application/json;charset=UTF-8" )
    public HytResponse addMallGoods(
            @ApiParam(value = "商品实体对象",required = true)
            @ModelAttribute MallGoods mallGoods){
        HytResponse hytResponse = null;
        MallGoods mg = new MallGoods();
        mg.setGoodsNo(mallGoods.getGoodsNo());
        mg.setGoodsName(mallGoods.getGoodsName());
        mg.setDescription(mallGoods.getDescription());
        mg.setStatus(mallGoods.getStatus());
        mg.setCategory(mallGoods.getCategory());
        mg.setUnit(mallGoods.getUnit());
        mg.setColor(mallGoods.getColor());
        mg.setSize(mallGoods.getSize());
        mg.setSellPrice(mallGoods.getSellPrice());
        mg.setPackageType(mallGoods.getPackageType());
        mg.setWeight(mallGoods.getWeight());
        mg.setOriginPrice(mallGoods.getOriginPrice());
        mg.setOperater(mallGoods.getOperater());
        mg.setViewTimes(mallGoods.getViewTimes());
        mg.setPurchaseTimes(mallGoods.getPurchaseTimes());
        mg.setInventory(mallGoods.getInventory());
        mg.setPutawayStatus(mallGoods.getPutawayStatus());
        mg.setCheapStatus(mallGoods.getCheapStatus());
        mg.setDiscountStatus(mallGoods.getDiscountStatus());
        mg.setIsRecommend(mallGoods.getIsRecommend());
        mg.setIsHot(mallGoods.getIsHot());
        mg.setIsNew(mallGoods.getIsNew());

        return hytResponse;
    }*/



    @ApiOperation(value = "商城首页列表",notes="商城首页列表",httpMethod ="GET")
    @RequestMapping(value = "/getMallIndex",method = {RequestMethod.GET},produces ="application/json;charset=UTF-8" )
    public HytResponse<List<MallGoods>> getMallGoodsIndex(
            @ApiParam(value = "商品实体对象",required = true)
            @ModelAttribute MallGoods mallGoods){
        HytResponse<List<MallGoods>> hytResponse = null;
        try {
            List<MallGoods> goodsList = mallGoodsService.getMallGoodsIndex(mallGoods);
            hytResponse = ResponseResultHandler.handleSuccess(goodsList);
        }catch (BaseBizException e){
            logger.info(e.getMessage(), e);
            hytResponse = ResponseResultHandler.handleError(ResponseResultHandler.RES_FAIL, ExceptionCode.BASE_SYSWRONG.getMessage());
        }
        return hytResponse;
    }

    @ApiOperation(value = "商品详情",notes = "获取商品详情",httpMethod = "GET")
    @ResponseBody
    @RequestMapping(value = "/getGoodsDetail",method = {RequestMethod.GET},produces ="application/json;charset=UTF-8")
    public HytResponse<MallGoods> getGoodsDetail(
            @ApiParam(value = "商品ID",required = true)
            @RequestParam(value = "goodsId",required = true)
            Integer goodsId){
        MallGoods mallGoods=mallGoodsService.getGoodsById(goodsId);
        HytResponse hytResponse=ResponseResultHandler.handleSuccess(mallGoods);
        hytResponse.setMessage("获取成功");
        return hytResponse;
    }
}
